<template>
	<view>
		<navbar title="贷款申请" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__box">
					<view class="con__box__title">
						<image src="/static/daikuan/dkicon.png" class="con__box__title__icon" mode=""></image>
						借款金额
					</view>
					<view class="con__box__money">
						￥
						<input type="number" class="con__box__money__inp" v-model="form.dedamount" />
					</view>
					<view class="con__box__item u-flex u-flex-between" @click="navto('/pages/customer/checkxs')">
						<view class="con__box__item__label">
							销售
						</view>
						<view class="" style="flex: 1;margin-right: 10rpx;">
							<view class="con__box__item__inp" v-if="curuser.manager_name">
								{{curuser.manager_name}}
							</view>
							<view class="con__box__item__inp" style="color: rgb(109, 109, 109);" v-else>
								请选择销售
							</view>
						</view>
						<image src="/static/daikuan/more.png" class="con__box__item__more" mode=""></image>
					</view>
					<view class="con__box__item">
						<view class="con__box__item__line">

						</view>
						<view class="con__box__item__label" style="color:#1E1E1E;">
							基本信息
						</view>
					</view>
					<view class="con__box__item" v-for="(item,index) in formdata" :key="index">
						<view class="con__box__item__label">
							{{item.label}}
						</view>
						<view class="con__box__item__inp" v-if="item.type=='data'">
							{{item.val}}
						</view>
						<view class="con__box__item__inp" v-if="item.type=='radio'">
							<view class="con__box__item__inp__r" v-for="(item1,index1) in item.rlist" :key="index1"
								@click="item.val=item1.name">
								<view class="con__box__item__inp__r__b">
									<image src="/static/daikuan/check.png" v-if="item1.name==item.val"
										class="con__box__item__inp__r__b__c" mode="">
									</image>
									<view class="con__box__item__inp__r__b__n" v-else>
						
									</view>
								</view>
								{{item1.name}}
							</view>
						</view>
						<input type="text" class="con__box__item__inp" v-if="item.type=='text'||item.type=='number'" v-model="item.val" :placeholder="'请填写'+item.label" />
					</view>
					<u-button color="#3262FD" text='提交申请' @click="submit" :loading="loading"
						:customStyle='{width:"628rpx",height:"94rpx",margin:"62rpx 0 0 0",padding:0,borderRadius:"15rpx",fontSize:"32rpx"}'></u-button>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				formdata: [{
						label: '姓名',
						val: '',
						type: 'text',
						name:'username'
					},
					{
						label: '电话',
						val: '',
						type: 'number',
						name:'mobile',
						maxlength:11,
						
					},
					{
						label: '房产情况',
						val: '',
						type: 'radio',
						name:'house',
						rlist: [{
							name: '有',
						}, {
							name: '无',
						}]
					},
					{
						label: '车辆情况',
						val: '',
						type: 'radio',
						name:'car',
						rlist: [{
							name: '有',
						}, {
							name: '无',
						}]
					},
					{
						label: '工作单位',
						val: '',
						type: 'text',
						name:'company'
					},
					{
						label: '工作职位',
						val: '',
						type: 'text',
						name:'role'
					},
					{
						label: '月收入',
						val: '',
						type: 'text',
						name:'salary'
					},
					{
						label: '婚姻状况',
						val: '',
						type: 'radio',
						name:'marriage',
						rlist: [{
							name: '已婚',
						}, {
							name: '未婚',
						}]
					},
					{
						label: '社保',
						val: '',
						type: 'radio',
						name:'sb',
						rlist: [{
							name: '有',
						}, {
							name: '无',
						}]
					},
					{
						label: '公积金',
						val: '',
						type: 'radio',
						name:'gjj',
						rlist: [{
							name: '有',
						}, {
							name: '无',
						}]
					},
					{
						label: '负债情况',
						val: '',
						type: 'text',
						name:'debt'
					},
				],
				curuser:{},
				form:{
					type:1, //enum('1','2') DEFAULT '1' COMMENT '类型:1=客户提交,2=销售提交',
					username:'', //varchar(32) DEFAULT NULL COMMENT '姓名',
					mobile:'',
					sale_id:'', //int(11) DEFAULT NULL COMMENT '销售ID',
					dedamount:'', //varchar(255) DEFAULT NULL COMMENT '需求金额',
					house:'', //json DEFAULT NULL COMMENT '房产情况',
					car:'', //json DEFAULT NULL COMMENT '车辆情况',
					company:'', //varchar(32) DEFAULT NULL COMMENT '工作单位',
					role:'', //varchar(255) DEFAULT NULL COMMENT '工作职位',
					salary:'', //decimal(10,2) DEFAULT NULL COMMENT '薪资',
					marriage:'', //varchar(255) DEFAULT NULL COMMENT '婚姻情况',
					sb:'', //varchar(255) DEFAULT NULL COMMENT '社保',
					gjj:'', //varchar(255) DEFAULT NULL COMMENT '公积金',
					debt:'' //varchar(255) NOT NULL COMMENT '负债金额',
				},
				loading:false
			};
		},
		methods: {
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			async submit(){
				this.formdata.map(t=>{
					for (let key in this.form) {
						if(t.name==key){
							this.form[key]=t.val
						}
					}
				})
				this.form.sale_id=this.curuser.manager_id
				if (!this.paramsValidate(this.form)) {
					return
				}
				this.loading=true
				let _this = this
				let res = await user.createLoan(this.form)
				if(res.data.code==1){
					uni.$u.toast('提交成功，等待审核')
					setTimeout(()=>{
						uni.navigateBack()
						_this.loading=false
					},1000)
				}else{
					_this.loading=false
				}
			},
			paramsValidate(params) {
				let flag = true;
				for (var key in params) {
					if (params[key] != '0' && !params[key]) {
						uni.$u.toast('请将信息填写完整')
						return false; // 终止程序
					}
				}
				return flag;
			},
		},
		onShow() {
			if(this.$store.state.curuser){
				this.curuser=this.$store.state.curuser
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.con {
		padding: 20rpx 30rpx 50rpx;

		&__box {
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 33rpx 0 46rpx 30rpx;

			&__title {
				display: flex;
				align-items: center;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #1E1E1E;
				line-height: 30rpx;

				&__icon {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					margin-right: 14rpx;
				}
			}

			&__ti {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #1E1E1E;
				line-height: 26rpx;
				display: flex;
				align-items: center;
				padding: 35rpx 0 30rpx;
				padding-left: 10rpx;

				&__line {
					width: 6rpx;
					height: 24rpx;
					background: #3262FD;
					margin-right: 10rpx;
				}
			}

			&__money {
				display: flex;
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 36rpx;
				color: #010101;
				line-height: 40rpx;
				align-items: center;
				margin: 30rpx 0 0;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #F9F9F9;

				// margin-top: 10rpx;
				&__inp {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 53rpx;
					color: #000000;
					line-height: 40rpx;
					margin-left: 6rpx;
				}
			}

			&__item {
				height: 106rpx;
				padding: 0 30rpx 0 0;
				display: flex;
				align-items: center;
				// justify-content: space-between;
				border-bottom: 2rpx solid #F9F9F9;

				&__more {
					width: 12rpx;
					height: 21rpx;
				}

				&__line {
					width: 5rpx;
					height: 24rpx;
					background: #3262FD;
					margin-right: 10rpx;
				}

				&__label {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #6D6D6D;
					line-height: 26rpx;
				}

				&__inp {
					flex: 1;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #020202;
					line-height: 38rpx;
					text-align: right;
					display: flex;
					align-items: center;
					justify-content: flex-end;

					.uni-input-placeholder {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #6D6D6D;
						line-height: 38rpx;
					}

					&__timelabel {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #6D6D6D;
						line-height: 38rpx;
					}

					&__r {
						display: flex;
						align-items: center;
						margin-left: 50rpx;

						&__b {
							display: flex;
							align-items: center;
							justify-content: center;
							margin-right: 9rpx;

							&__c {
								width: 28rpx;
								height: 28rpx;
								border-radius: 50%;
							}

							&__n {
								width: 24rpx;
								height: 24rpx;
								border-radius: 50%;
								border: 2rpx solid #6D6D6D;
								opacity: 0.5;
							}
						}
					}
				}
			}
		}
	}

	::v-deep.u-textarea {
		padding: 32rpx 30rpx 60rpx 0;

		.u-textarea__field {
			font-size: 26rpx;
			color: #020202;
		}

		.uni-textarea-placeholder {
			color: #939393 !important;
		}
	}
</style>